package ca.llsutherland.nfl.persistence;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import javax.naming.NamingException;

import ca.llsutherland.nfl.configuration.PoolConfiguration;

import com.mysql.jdbc.Driver;

public class HomegrownDatabaseConnection extends AbstractDatabaseConnection {

	private static DatabaseConnectionInterface instance = new HomegrownDatabaseConnection();

    public DatabaseConnectionInterface getInstance() {
        return instance ;
    }

    public void initializeConnection() throws SQLException, NamingException {
        if (getCurrentConnection() == null) {
            Driver driver = null;
            try {
                driver = (Driver)Class.forName(PoolConfiguration.getInstance().getDatabaseDriver()).newInstance();
            } catch (InstantiationException e) {
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            }
            DriverManager.registerDriver(driver);
            String url = PoolConfiguration.getInstance().getDatabaseUrl();
            String username = PoolConfiguration.getInstance().getDbUsername();
            String password = PoolConfiguration.getInstance().getDbPassword();
            Connection connection = DriverManager.getConnection(url, username , password );
            setCurrentConnection(connection);
        }
    }

    @Override
    public void registerNewDomainObject(Long id, String tableName) {
        //never do anything here
    }

    @Override
    public void deleteNewDomainObjects() {
        //never do anything here
    }

    @Override
    public void removeDomainObject(Long idToRemove) {
        //never do anything here
    }

}
